package cn.tedu.ivos.geofence.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceQuery;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceSaveParam;
import cn.tedu.ivos.geofence.pojo.vo.GeofenceVO;
import cn.tedu.ivos.geofence.service.GeofenceService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "围栏模块")
@Slf4j
@RestController
@RequestMapping("/v1/geofence")
public class GeofenceController {
    @Autowired
    GeofenceService geofenceService;

    @Operation(summary = "围栏查询")
    @ApiOperationSupport(order = 10)
    @GetMapping("select")
    public JsonResult selectUser(GeofenceQuery geofenceQuery){
        log.debug("开始处理用户查询的请求，参数：{}",geofenceQuery);
        List<GeofenceVO> list = geofenceService.selectGeofence(geofenceQuery);
        return JsonResult.ok(list);
    }
    @Operation(summary = "修改围栏状态")
    @ApiOperationSupport(order = 20)
    @PostMapping("changeStatus/{geofenceId}/{status}")
    public JsonResult updateStatus(@PathVariable Long geofenceId, @PathVariable String status){
        log.debug("开始处理围栏修改状态的请求，参数：{}",geofenceId);
        geofenceService.updateStatus(geofenceId,status);
        return JsonResult.ok();
    }
    @Operation(summary = "删除围栏")
    @ApiOperationSupport(order = 30)
    @PostMapping("delete/{id}")
    public JsonResult delete(@PathVariable Long id){
        log.debug("开始处理删除围栏的请求，参数：{}",id);
        geofenceService.deleteGeofence(id);
        return JsonResult.ok();
    }
    @Operation(summary = "添加围栏")
    @ApiOperationSupport(order = 40)
    @PostMapping("save")
    public JsonResult saveGeofence(@Validated GeofenceSaveParam geofenceSaveParam){
        log.debug("开始处理添加围栏的请求，参数：{}",geofenceSaveParam);
        geofenceService.saveGeofence(geofenceSaveParam);
        return JsonResult.ok();
    }
}
